#include "deletefilecommand.h"

#include <QFile>
#include <QFileInfo>
#include <QDomDocument>
#include <QDebug>

DeleteFileCommand::DeleteFileCommand(const QString &filePath):
		m_FilePath(filePath)
{
}

bool DeleteFileCommand::doCommand(QString &responseData)
{
	QDomDocument resultXml;
	QDomElement rootElement = resultXml.createElement("Result");
	resultXml.appendChild(rootElement);

	QFileInfo fileInfo(m_FilePath);
	int result = 0;
	if(fileInfo.isFile())
	{
		QFile deleteFile(m_FilePath);
		if(!deleteFile.remove())
		{
			result = 0;
		}
		else
		{
			result = 1;
		}
	}
	else
	{
		int ret = ::system( ("rmdir /S /Q " + m_FilePath).toStdString().c_str() );
		result = ret == 0? 1: 0;
	}
	rootElement.setAttribute("Result", result);
	responseData.append(resultXml.toString());
	return true;
}
